package com.gitee.devinx3.mrg.controller;

import com.gitee.devinx3.mrg.entity.Organization;
import com.gitee.devinx3.mrg.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/organizations/{organizationId}")
public class OrganizationController {

    @Autowired
    private OrganizationService orgService;

    @GetMapping
    public Organization getOrganization(@PathVariable("organizationId") String organizationId) {
        return orgService.getOrg(organizationId);
    }

    @PutMapping
    public void updateOrganization(@PathVariable("organizationId") String organizationId, @RequestBody Organization org) {
        org.setId(organizationId);
        orgService.updateOrg(org);
    }

    @PostMapping
    public void saveOrganization(@RequestBody Organization org) {
        orgService.saveOrg(org);
    }

    @DeleteMapping
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteOrganization(@PathVariable("organizationId") String organizationId) {
        orgService.deleteOrg(organizationId);
    }

}
